package com.relax.netty.nio;

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * mappedbytebuffer 文件和堆外内存的映射,我们可以直接操作堆外内存,然后文件也会改变
 */
public class NioTest9 {
    public static void main(String[] args) throws Exception {
        RandomAccessFile randomAccessFile = new RandomAccessFile("test9.txt", "rw");
        FileChannel channel = randomAccessFile.getChannel();
        /**
         * 参数1:什么映射模式
         * 参数2:映射起始位置
         * 参数3:长度
         */
        MappedByteBuffer mappedByteBuffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, 5);
        /**
         * 修改mappedByteBuffer内存的数据
         */
        mappedByteBuffer.put(0,(byte)'a');
        mappedByteBuffer.put(1,(byte)'b');

        randomAccessFile.close();


    }
}
